/*
 * Author: Sinclair Ross
 * Functionality implemented by: Neil Wicker and Sinclair Ross
 * Description: Initialise the board by setting the tiles in a 5x5 formation. Include getters and setters 
 */

package com.forbiddendesert.logic;

import java.util.Random;
import java.util.Vector;

import com.forbiddendesert.tiles.GearTile;
import com.forbiddendesert.tiles.Tile;

import android.content.Context;


public class Board 
{
	private static int TILE_SIZE = 100;
	private static final int NUM_ROWS = 5;
	private static final int NUM_COLUMNS = 5;
	
	private Vector<Tile> mTiles;

	public Board(Context context)
	{
		mTiles = new Vector<Tile>(25);
		fillBoard(context);
	}
	
	private void fillBoard(Context context)
	{
		Vector<Tile> TileList = new Vector<Tile>();
		Tile ActiveTile;
		Random rand = new Random();
		
		for(int i = 0; i < 24; i++) 
		{
			TileList.add(new GearTile(context));
		}
		
		for(int x = 0; x < NUM_COLUMNS; x++)
		{
			for(int y = 0; y < NUM_ROWS; y++)
			{
				// If not in the centre of the board.
				if(x != 2 || y != 2)	
				{
					if(TileList.size() > 0)
					{
					// Get random integer that relates to a position in TileList.
						int index = rand.nextInt(TileList.size());	
						ActiveTile = TileList.elementAt(index);
					}
					else
					{
						ActiveTile = TileList.elementAt(0);
					}
					
					ActiveTile.setPosition(x*TILE_SIZE, y*TILE_SIZE);
					
					mTiles.add(ActiveTile);
					TileList.remove(ActiveTile);
				}
			}
		}
		
		TileList = null;
		rand = null;
	}
	
	public Vector<Tile> getTiles()
	{
		return mTiles;
	}
	
	public Tile getTile(int x, int y)
	{
		return null;
	}

	public int getNumRows()
	{
		return NUM_ROWS;
	}
	
	public int getNumColumns()
	{
		return NUM_COLUMNS;
	}
	
	public void moveStorm()
	{
		// TODO:
	}
}
